package mybatis.web;

import mybatis.pojo.Page;
import mybatis.pojo.Student;
import mybatis.services.StudentService;
import mybatis.util.StrUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

/**
 * @Author 汤舒青
 * @Version 1.0
 */

@WebServlet("/student")
public class StudentServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String stuName = request.getParameter("stuName");
        stuName = stuName == null ? "" : stuName;
        int pageNo = StrUtil.toInt(request.getParameter("pageNo"), 1);
        String wechat=StrUtil.toStr(request.getParameter("wechat"));
        String qq=StrUtil.toStr(request.getParameter("qq"));
        Date start=StrUtil.toDate(request.getParameter("start"));
        Date end=StrUtil.toDate(request.getParameter("end"));
        Page<Student> student = StudentService.ME.showStuLike(pageNo,wechat,qq,stuName,start,end);
        request.setAttribute("pageNo",pageNo);
        request.setAttribute("wechat",wechat);
        request.setAttribute("qq",qq);
        request.setAttribute("start",start);
        request.setAttribute("page",student);
        request.setAttribute("stuName",stuName);
        //req.setAttribute("grades",all);
        request.getRequestDispatcher("/WEB-INF/jsp/studentServlet.jsp").forward(request,resp);
    }
}
